package src.java.easy;

public class Solution66 {
    public int[] plusOne(int[] digits) {
        int index = digits.length - 1;
        for (int i = index; i >= 0; i--) {
            if(digits[i]<9){
                digits[i]++;
                break;
            }else{
                digits[i]=0;
                if(i==0){
                    int[] result = new int[digits.length+1];
                    result[0]=1;
                    for(int j=1;j<result.length;j++){
                        result[j]=digits[j-1];
                    }
                    return result;
                }
            }
        }
        return digits;
    }
}
